package crm.controlle;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import crm.dao.UserDao;
import crm.entity.SysUs;
import crm.service.UserService;



@Controller
@RequestMapping("/User")
public class UserControlle {
	
	@Autowired
	private UserService userService;
	
	
	@RequestMapping(value="/getlogin",method=RequestMethod.GET)
	public ModelAndView getlogin(HttpServletRequest request,SysUs sysus){
		SysUs sys = userService.getlogin(sysus);
		if(sys==null){
			return new ModelAndView("login", "error", "用户名或密码错误。");
		}else{
			request.getSession().setAttribute("sys", sys);
		}

		return new ModelAndView("index");
	}
	
	@RequestMapping(value="/getOutlogin",method=RequestMethod.GET)
	public String getOutlogin(HttpServletRequest request,SysUs sysus){
		request.getSession().removeAttribute("sys");
		return "login";
	}

}
